/**
* <p> title �� ScheduleServiceImpl.java</p>
* <p> package �� cn.edu.hit.education.service</p>
* <p> description ��TODO</p>
* <p> copyright �� ��������ҵ��ѧ(C) 2019</p>
* <p> company �� ��������ҵ��ѧAS&MT</p>
* <p> author �� ��ѩ�� jinxuesong@163.com</p>
* <p> date �� 2021��4��21�� ����4:40:39</p>
* <p> version �� v1.0 </p>
*
* Modification  History:
* Date         Author        Version        Discription
* -----------------------------------------------------------------------------------
* 2021��4��21��       ��ѩ��          1.0             1.0
* Why & What is modified: <�޸�ԭ������>
*/
package cn.edu.hit.education.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.hit.education.dao.ScheduleMapper;
import cn.edu.hit.education.pojo.Course;
import cn.edu.hit.education.pojo.ExSchedule;
import cn.edu.hit.education.pojo.Schedule;
import cn.edu.hit.education.pojo.ScheduleExample;
import cn.edu.hit.education.utils.StatisticsUtil;

@Service
public class ScheduleServiceImpl implements IScheduleService {

	@Autowired
	ScheduleMapper scheduleMapper;
	@Autowired
	ICourseService courseService;

	@Override
	public int insert(Schedule schedule) {
		return scheduleMapper.insert(schedule);
	}
	@Override
	public int deleteByPrimaryKey(int id) {
		return scheduleMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int update(Schedule schedule) {
		return scheduleMapper.updateByPrimaryKey(schedule);
	}

	@Override
	public List<Schedule> queryAllSchedule() {
		ScheduleExample example = new ScheduleExample();
		ScheduleExample.Criteria criteria = example.createCriteria();
		criteria.andIdGreaterThan(0);
		
		return scheduleMapper.selectByExample(example);
	}

	@Override
	public List<Schedule> querySchedulesBySpecialtySemesterId(int specialtyId,
			int semesterId) {
		ScheduleExample example = new ScheduleExample();
		ScheduleExample.Criteria criteria = example.createCriteria();
		criteria.andSpecialtyIdEqualTo(specialtyId);
		criteria.andSemesterIdEqualTo(semesterId);
		
		return scheduleMapper.selectByExample(example);
	}
	
	@Override
	public List<Schedule> querySchedulesBySpecialtySemesterCourseId(
			int specialtyId, int semesterId, int courseId) {
		ScheduleExample example = new ScheduleExample();
		ScheduleExample.Criteria criteria = example.createCriteria();
		criteria.andSpecialtyIdEqualTo(specialtyId);
		criteria.andSemesterIdEqualTo(semesterId);
		criteria.andCourseIdEqualTo(courseId);
		
		return scheduleMapper.selectByExample(example);
	}

	@Override
	public List<Schedule> querySchedulesBySpecialtyCourseId(int specialtyId,int courseId) {
		ScheduleExample example = new ScheduleExample();
		ScheduleExample.Criteria criteria = example.createCriteria();
		criteria.andSpecialtyIdEqualTo(specialtyId);
		criteria.andCourseIdEqualTo(courseId);
		
		return scheduleMapper.selectByExample(example);
	}
	
	@Override
	public List<Schedule> querySchedulesBySpecialtyId(int specialtyId,int opened) {
		ScheduleExample example = new ScheduleExample();
		ScheduleExample.Criteria criteria = example.createCriteria();
		criteria.andSpecialtyIdEqualTo(specialtyId);
		criteria.andOpenedEqualTo(opened);
		
		return scheduleMapper.selectByExample(example);
	}
	
	@Override
	public void statisticsSchedule(int specialtyId,int opened) {
	}
	
	@Override
	public Schedule qurySchedule(int courseId) {
		// TODO Auto-generated method stub
		
		
		return (scheduleMapper.queryCourseByCourseId(courseId));
	}
	@Override
	public List<Schedule> querySchedulesBySemesterCourseId(Integer semesterId,
			Integer courseId) {
		// TODO Auto-generated method stub
		ScheduleExample example = new ScheduleExample();
		ScheduleExample.Criteria criteria = example.createCriteria();
		criteria.andSemesterIdEqualTo(semesterId);
		criteria.andCourseIdEqualTo(courseId);
		
		return scheduleMapper.selectByExample(example);
	}
	@Override
	public List<Schedule> querySchedulesBySemesterId(int semesterId) {
		// TODO Auto-generated method stub
		ScheduleExample example = new ScheduleExample();
		ScheduleExample.Criteria criteria = example.createCriteria();
		criteria.andSemesterIdEqualTo(semesterId);
		
		return scheduleMapper.selectByExample(example);
	}
	@Override
	public List<Schedule> querySchedulesBySCourseId(Integer courseId) {
		// TODO Auto-generated method stub
		ScheduleExample example = new ScheduleExample();
		ScheduleExample.Criteria criteria = example.createCriteria();
		
		criteria.andCourseIdEqualTo(courseId);
		
		return scheduleMapper.selectByExample(example);
	}
	
	@Override
	public List<ExSchedule> queryExSchedulesBySpecialtySemesterId(
			int specialtyId, int semesterId) {
		List<ExSchedule> exSchedules = new ArrayList<ExSchedule>();
		List<Schedule> schedules = querySchedulesBySpecialtySemesterId(specialtyId, semesterId);
		for (Schedule schedule : schedules) {
			ExSchedule exSchedule = new ExSchedule();
			exSchedule.setId(schedule.getId());
			exSchedule.setSpecialtyId(schedule.getSpecialtyId());
			exSchedule.setSemesterId(schedule.getSemesterId());
			exSchedule.setCourseId(schedule.getCourseId());
			exSchedule.setOpened(schedule.getOpened());
			exSchedule.setCredits(schedule.getCredits());
			exSchedule.setPeriod(schedule.getPeriod());
			exSchedule.setTheoretical(schedule.getTheoretical());
			exSchedule.setExperiment(schedule.getExperiment());
			exSchedule.setNote(schedule.getNote());
			exSchedule.setCourse(courseService.queryCourseByPrimaryKey(schedule.getCourseId()));
			exSchedules.add(exSchedule);
		}
		return exSchedules;
	}

}
